package org.gdsdxy.pmmp.service;

import java.util.List;

import org.gdsdxy.pmmp.dao.IUserManagerDao;
import org.gdsdxy.pmmp.entity.Email;
import org.gdsdxy.pmmp.entity.MemberBaseInfo;
import org.gdsdxy.pmmp.entity.MemberImge;
import org.gdsdxy.pmmp.page.PageResult;

public class UserManagerServiceImpl implements IUserManagerService {
	
	//ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
	private IUserManagerDao dao ;//(IUserManagerDao) ac.getBean("daoByHbn");
	
	
	
	public void setDao(IUserManagerDao dao) {
		System.out.println("注入Dao:"+dao);
		this.dao = dao;
	}

	public MemberBaseInfo login(String userName, String password) {
		
		if("".equals(userName) || userName==null || "".equals(password) || password==null){
			return null;
		}
		return  dao.queryMemberBaseInfo(userName, password);
		
	}

	public boolean addMemberImge(MemberImge imge) {
		if(imge==null){
			return false;
		}
		return dao.saveMemberImge(imge);
	}

	public List<MemberImge> getMemberImgeByUserId(Integer id) {
		if(id==null|| id==0)
		return null;
		
		 return  dao.queryImgeByUserId(id);
	
	}

	public long getImageCountById(Integer id) {
		if(id==null || id==0)
		return 0;
		return dao.getImageCountById(id);
	}

	public PageResult<MemberImge> queryImgeByUserIdFy(int start, int size, Integer id) {
		if(id==null || id==0)
			return null;
		PageResult<MemberImge> memberImages = new PageResult<MemberImge>(dao.queryImgeByUserIdFy(start, size, id),this.getImageCountById(id));
		return memberImages;
	}
	
  public List<MemberBaseInfo> queryLatestUsers(){
    return dao.queryUsers(0, 8);
  }

@Override
public boolean addMemberBaseInfo(MemberBaseInfo baseInfo) {
	return dao.saveMemberBaseInfo(baseInfo);
}

public MemberBaseInfo get(Integer id) {
  
  return dao.get(id);
}

}
